﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WHO_Auth_TNG_Win {
    public partial class PasswordDialog : Form {
        Auth auth;
        public PasswordDialog(Auth auth) {
            this.auth = auth;
            InitializeComponent();
        }

        private void buttonOk_Click(object sender, EventArgs e) {
            if (!textPassword.Text.Equals("")) {
                if (checkSavePassword.Checked) {
                    WHT_Auth.Properties.Settings.Default.password = Base64.Encode(textPassword.Text);
                }
                WHT_Auth.Properties.Settings.Default.savePassword = checkSavePassword.Checked;
                WHT_Auth.Properties.Settings.Default.Save();
                auth.password = textPassword.Text;
                this.Close();
            }
        }

        private void buttonCancel_Click(object sender, EventArgs e) {
            MessageBox.Show("WHO-Auth TNG will start but not work until you provide a password in the options settings.", "Credentials incomplete", MessageBoxButtons.OK);
            this.Close();
        }

        private void textPassword_KeyPress(object sender, KeyPressEventArgs e) {
            if (e.KeyChar == '\r') {
                buttonOk_Click(sender, null);
            }
        }
    }
}
